package com.pwt.controller.permission;

import com.pwt.annotation.Update;
import com.pwt.common.CustomException;
import com.pwt.common.DataNotFoundException;
import com.pwt.entity.Menu;
import com.pwt.model.MenuTreeModel;
import com.pwt.service.MenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "权限菜单管理")
public class MenuController {

    @Autowired
    MenuService menuService;

    @PostMapping("menus")
    @Operation(description = "增加菜单",summary = "新增菜单")
    public Menu add(@RequestBody @Validated Menu menu) throws CustomException {
        return menuService.add(menu);
    }

    @GetMapping("menus/tree")
    @Operation(description = "查询菜单",summary = "查询树形结构菜单")
    public MenuTreeModel tree() {
        return menuService.tree();
    }

    @PutMapping("menus")
    @Operation(description = "修改菜单",summary = "修改菜单")
    public Menu edit(@RequestBody @Validated(value = Update.class) Menu menu)  throws CustomException {
        return menuService.edit(menu);
    }

    @DeleteMapping("menus/{id}")
    @Operation(description = "删除菜单",summary = "删除菜单")
    public String delete(@PathVariable @Parameter(description = "菜单ID") String id) throws CustomException {
        return menuService.delete(id);
    }
}
